package com.leetcode.merci.lc053;

/**
 * Created by bowen on 2017/7/25.
 */
public class Solution {
    public int maxSubArray(int[] nums) {
        int l=nums.length;
        if(l==0) return 0;
        int[] dp=new int[l];
        dp[0]=nums[0];
        int max=dp[0];
        for(int i=1;i<l;i++){
            dp[i]=dp[i-1]>0?dp[i-1]+nums[i]:nums[i];
            if(dp[i]>max)
                max=dp[i];
        }
        return max;
    }
}